$(function () {
	init();
	listenbutton();
});

function listenbutton() {
	$("#submit").click(function () {
		$.ajax({
			cache: true,
			type: "POST",
			url: "../User/ModifyPassword",
			data: $('#myFrom').serialize(), // 你的formid
			async: false,
			error: function (request) {
				alert("修改失败");
			},
			success: function (data) {
				if (data =="success") {
					alert("修改成功");
				} else {
					alert("修改失败");
				}
			}
		});

	})


}


function init() {
	var validator = $("#myFrom").bind(
		"invalid-form.validate",
		function () {
			$("#validateForm").html(
				"表单包含 " + validator.numberOfInvalids() + "个错误！");
		}).validate({
		//debug : true,
		errorElement: "span",
		errorPlacement: function (error, element) {
			error.appendTo(element.parent("div").next(
				"label.control-label-left"));
		},
		success: function (label) {
			label.html('<i class="glyphicon glyphicon-ok"></i>');
		},
		rules: {
			oldPassword: {
				required: true,
				minlength: 3,
				maxlength: 20
			},
			newPassword: {
				required: true,
				minlength: 3,
				maxlength: 20
			},
			secondPassword: {
				equalTo: "#newPassword",

			}
		},
		messages: {
			oldPassword: {
				required: "旧密码为必填选项",
				minlength: "密码最少为3位",
				maxlength: "密码不超过为20位"
			},
			newPassword: {
				required: "新密码为必填选项",
				minlength: "密码最少为3位",
				maxlength: "密码不超过为20位"
			},
			secondPassword: {
				equalTo: "两次密码不一致",

			}
		}
	});
}